//
//  HWXiaoHaoCustomHeadFooterView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/11/14.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWXiaoHaoCustomHeadFooterView.h"
#import "HWXiaoGroupModel.h"
@interface HWXiaoHaoCustomHeadFooterView()
@property(strong,nonatomic) UILabel *datelabel;
@property(strong,nonatomic) UILabel *jifenLabe;
@property(strong,nonatomic) UILabel *xiugailabel;
@property(strong,nonatomic) UIView *zuixianbianfengexxianView;
@property(strong,nonatomic) UIButton *deleteBut;
@property(strong,nonatomic) UIButton *sellBut;



@end

@implementation HWXiaoHaoCustomHeadFooterView

+ (instancetype)headFooterViewWithTableview:(UITableView *)tableview {
    
    HWXiaoHaoCustomHeadFooterView *view = [tableview dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([HWXiaoHaoCustomHeadFooterView class])];

      if (view == nil) {
          view = [[HWXiaoHaoCustomHeadFooterView alloc]initWithReuseIdentifier:NSStringFromClass([HWXiaoHaoCustomHeadFooterView class])];
      }
   //   view.backgroundColor = [UIColor yellowColor];
      return view;
    
}



- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    if(self = [super initWithReuseIdentifier:reuseIdentifier]){
        
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
       
  
                   self.datelabel  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW/3, 44)];
                   self.datelabel.text = @"1";
                   self.datelabel.font = [UIFont systemFontOfSize:10];
                   self.datelabel.textColor = RGB(102,102,102);
                   self.datelabel.numberOfLines = 2;
                   self.datelabel.textAlignment = NSTextAlignmentCenter;
                    self.datelabel.userInteractionEnabled =YES;
                   [self.contentView addSubview:self.datelabel];
                  UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianjizhankai)];
                  [self.datelabel addGestureRecognizer:tap1];
        
        
        
        
                  
                  self.jifenLabe  = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW/3, 0, kScreenW/3, 44)];
                  self.jifenLabe.text = @"+50";
                  self.jifenLabe.font = [UIFont systemFontOfSize:10];
                  self.jifenLabe.textColor = RGB(102,102,102);
                  self.jifenLabe.numberOfLines = 2;
                  self.jifenLabe.textAlignment = NSTextAlignmentCenter;
                 self.jifenLabe.userInteractionEnabled = YES;
                  [self.contentView addSubview:self.jifenLabe];
                  
                  UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianjizhankai)];
                  [self.jifenLabe addGestureRecognizer:tap2];
           
            
                  

                     
                  
                  
                  
                  
                  
                
                   UIView *shuxian2 = [[UIView alloc]initWithFrame:CGRectMake(kScreenW/3*1, 0, 1, 44)];
                   shuxian2.backgroundColor = RGB(232, 232, 242);
                   [self.contentView addSubview:shuxian2];
                
                
                  UIView *shuxian3 = [[UIView alloc]initWithFrame:CGRectMake(kScreenW/3*2, 0, 1, 44)];
                  shuxian3.backgroundColor = RGB(232, 232, 242);
                  [self.contentView addSubview:shuxian3];
                  
                  
                   
                  UIView *fengexianview21 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
                  fengexianview21.backgroundColor = RGB(232, 232, 242);
                   
                  [self.contentView addSubview:fengexianview21];
        
               
                  UIView *fengexianview1 = [[UIView alloc]initWithFrame:CGRectMake(0, 43, kScreenW, 1)];
                  fengexianview1.backgroundColor = RGB(232, 232, 242);
                  self.zuixianbianfengexxianView = fengexianview1;
                  [self.contentView addSubview:fengexianview1];
        
        
             
                
                
                   CGFloat w =  (kScreenW/3 - 25*2)/3;
                   self.deleteBut = [UIButton buttonWithType:UIButtonTypeCustom];
                   self.deleteBut.frame = CGRectMake((kScreenW)/3*2+w, 0, 25, 36);
        
               NSString *shanchu = [HWjianzhiduiObject keylocalization:@"删除"];
              [self.deleteBut setTitle:@"删除" forState:UIControlStateNormal];
               [self.deleteBut setTitle:shanchu forState:UIControlStateNormal];
        
                
                   self.deleteBut.titleLabel.font = [UIFont systemFontOfSize:12];
                   [self.deleteBut  setTitleColor:RGB(255, 21, 21) forState:UIControlStateNormal];
                  [self.deleteBut addTarget:self action:@selector(deletetap:) forControlEvents:UIControlEventTouchUpInside];
                
                
        
                   [self.contentView addSubview: self.deleteBut];
                
                
                
                   self.sellBut = [UIButton buttonWithType:UIButtonTypeCustom];
                   self.sellBut.frame = CGRectMake((kScreenW)/3*2+w*2+25, 0, 25, 36);
                   [self.sellBut setTitle:@"出售" forState:UIControlStateNormal];
        
                NSString *chushou  = [HWjianzhiduiObject keylocalization:@"出售"];
        
        [self.sellBut setTitle:chushou forState:UIControlStateNormal];
        
        
                   self.sellBut.titleLabel.font = [UIFont systemFontOfSize:12];
                  [self.sellBut  setTitleColor:RGB(253, 178, 50) forState:UIControlStateNormal];
                   // self.sellBut.backgroundColor  = [UIColor yellowColor];
                  [self.sellBut addTarget:self action:@selector(sellButtap:) forControlEvents:UIControlEventTouchUpInside];
                  [self.contentView addSubview: self.sellBut];
                
  
        
       
        
        
       
     }
     return self;
    
}

//当前控件的frame发生改变的时候会调用这个方法

- (void)layoutSubviews{
    [super layoutSubviews];
  
}

// 删除小号
- (void)deletetap:(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(delagateHeaderViewDidClickTitleButton:)]){
          [self.delegate delagateHeaderViewDidClickTitleButton:self];
      }
     
}

// 出售
- (void)sellButtap:(UIButton *)sender {
    
    [self.delegate chushouViewtititleButton:self];
    
    
}



-(void)setGroup:(HWXiaoGroupModel *)group {
    
    _group = group;
    self.datelabel.text = group.user_name;
    self.jifenLabe.text =group.reg_time;
    
   
    
}

- (void)dianjizhankai {
    
     self.group.visible = !self.group.isVisible;
    
    if (self.group.data.count > 0) {
        
    } else {
        
        [MBProgressHUD showError:@"该小号没有玩过游戏"];

    }
    
    if(self.delegate&&[self.delegate respondsToSelector:@selector(groupHeaderViewDidClickTitleButton:)]){
        [self.delegate groupHeaderViewDidClickTitleButton:self];
    }
   
    
    
}


@end
